﻿using System.Reflection;

namespace MiniCap.Abstractions;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class MiniCapSubscribeAttribute : Attribute
{
    public string Topic { get; }
    public MiniCapSubscribeAttribute(string topic) => Topic = topic;


    public static bool TryFromMethod(MethodInfo method, out string? topic)
    {
        var attr = method.GetCustomAttribute<MiniCapSubscribeAttribute>();
        topic = attr?.Topic;
        return topic != null;
    }
}

